<template>
  <section class="todoapp">
    <TodoHeader @kess="kessFn"></TodoHeader>
    <TodoMain :arr="lists" @san="sanFn"></TodoMain>
    <TodoFooter :arr="list" @eDl="eDlFn" @outs="outFn"></TodoFooter>
  </section>
</template>

<script>
import TodoFooter from "./components/TodoFooter.vue";
import TodoMain from "./components/TodoMain.vue";
import TodoHeader from "./components/TodoHeader.vue";
// 样式引入 + 导入组件并注册使用
import "./styles/base.css";
import "./styles/index.css";
export default {
  data() {
    return {
      type: "all",
      list: [
        {
          id: 100,
          name: "吃饭",
          isDone: true,
        },
        {
          id: 201,
          name: "睡觉",
          isDone: false,
        },
        {
          id: 103,
          name: "打豆豆",
          isDone: true,
        },
      ],
    };
  },
  components: {
    TodoFooter,
    TodoMain,
    TodoHeader,
  },
  methods: {
    sanFn(id) {
      console.log(id);
      this.list = this.list.filter((item) => item.id !== id);
    },
    kessFn(val) {
      this.list.unshift({
        id: +new Date(),
        name: val,
        isDone: false,
      });
    },
    eDlFn(val) {
      // console.log(val);
      this.type = val;
    },
    outFn() {
      this.list = this.list.filter((item) => item.isDone === false);
    },
  },
  computed: {
    lists() {
      if (this.type === "all") {
        return this.list;
      } else if (this.type === "active") {
        return this.list.filter((item) => item.isDone === false);
      } else if (this.type === "over") {
        return this.list.filter((item) => item.isDone === true);
      }
    },
  },
};
</script>
